<template>
  <div>
    <p style="font-size: 14px">首页</p>
    <div class="box">
      <div class="left">
        <div class="top_left">
          <div class="biandong">
            <p>今日数据变动</p>
          </div>
          <div class="table">
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.addCounts }}</span
                ><span>人</span>
              </div>
            </div>
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.courseCounts }}</span
                ><span>人</span>
              </div>
            </div>
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.leaveCounts }}</span
                ><span>人</span>
              </div>
            </div>
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.renewCounts }}</span
                ><span>人</span>
              </div>
            </div>
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.studentCounts }}</span
                ><span>人</span>
              </div>
            </div>
            <div class="table1">
              <div class="table_zi1">新增学员</div>
              <div class="table_zi2">
                <span class="abc">{{ jrbd.teacherCounts }}</span
                ><span>人</span>
              </div>
            </div>
          </div>
        </div>
        <div class="bottom_left">
          <div id="main" style="width: 100%; height: 100%"></div>
        </div>
      </div>
      <div class="right">
        <div class="top_right">
          <div class="top_right1">事项提醒</div>
          <div class="top_right2">
            <div class="zi1">续费</div>
            <div class="zi2">有一亿位学员剩余课时低于2</div>
          </div>
        </div>
        <div class="bottom_right">
          <div class="bottom_right1">生日学员</div>
          <div class="bottom_right2" v-for="item in todaycounts" :key="item.id">
            <div class="bottom_right2_img">
              <img
                :src="'https://api.eshareedu.cn/edusystems/upload/'+item.photo"
                alt=""
              />
            </div>
            <div class="left_right">
              <div class="left">{{ item.name }}</div>
              <div class="right">{{ item.birthday }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      jrbd: [],
      todaycounts: [],
    };
  },
  mounted() {
    this.list();
  },
  created() {
    this.bdlist();
    this.shengri();
  },
  methods: {
    //   生日学员
    async shengri() {
      const { data: res } = await this.$http.get(
        "http://www.eshareedu.cn/edusystems/api/students/birthday"
      );
      console.log(res);
      if (res.errCode != "10000") {
        this.$message.error("请求生日学员数据失败");
      }
      this.todaycounts = res.data.list;
    },
    //   生日学员
    //   今日变动数据
    async bdlist() {
      const { data: res } = await this.$http.get(
        "http://www.eshareedu.cn/edusystems/api/students/todaycounts"
      );
      // console.log(res.data.model);
      if (res.errCode != "10000") {
        this.$message.error("请求今日变动数据失败");
      }
      this.jrbd = res.data.model;
    },
    //   今日变动数据

    //   折线图
    async list() {
      // 请求折线图学生总数
      let monthlist = [];
      let zongshu = [];
      let danyue = [];
      const { data: res } = await this.$http.get(
        "http://www.eshareedu.cn/edusystems/api/students/allcounts?year=2021"
      );
      //    console.log(res)
      res.data.list.forEach((item) => {
        // console.log(item);
        monthlist.push(item.month);
        zongshu.push(item.counts);
      });
      //   console.log(monthlist);
      // 请求折线图学生总数

      //   请求折线图单月增加数量
      const { data: resa } = await this.$http.get(
        "http://www.eshareedu.cn/edusystems/api/students/monthcounts?year=2021"
      );
      //   console.log(resa);
      resa.data.list.forEach((item) => {
        danyue.push(item.counts);
      });
      //   console.log(danyue);
      //   请求折线图单月增加数量

      var chartDom = document.getElementById("main");
      var myChart = echarts.init(chartDom);
      var option = {
        title: {
          text: "",
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["学生总数", "单月增加"],
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: monthlist,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "学生总数",
            type: "line",
            data: zongshu,
          },
          {
            name: "单月增加",
            type: "line",
            data: danyue,
          },
        ],
      };

      option && myChart.setOption(option);
    },
    //   折线图
  },
};
</script>

<style  scoped lang="less">
.box {
  display: flex;
}

.left {
  margin-top: 0px;
  width: 1087px;
  height: 630px;
  /* background-color: coral; */
}
.left .top_left {
  margin-top: 10px;
  width: 1087px;
  height: 138px;
  background-color: rgb(255, 255, 255);
  .biandong {
    width: 72px;
    height: 45px;
    margin-left: 30px;
    //   background-color: red;
    p {
      font-size: 12px;
      color: #333;
      text-align: center;
      line-height: 45px;
    }
  }
  .table {
    width: 1028.04px;
    height: 80px;
    //   background-color: crimson;
    margin: auto;
    display: flex;
    .table1 {
      width: 171.34px;
      height: 80px;
      //   background-color: aqua;
      //   border: 1px 0.5px 1px 0.5px solid black;
      border-top: 1px solid rgb(241, 241, 241);
      border-bottom: 1px solid rgb(241, 241, 241);
      border-left: rgb(241, 241, 241) 1px solid;
      border-right: rgb(241, 241, 241) 1px solid;
      .table_zi1 {
        margin-top: 20px;
        width: 171.34px;
        height: 16px;
        // background-color: blue;
        text-align: center;
        line-height: 16px;
        font-size: 12px;
      }
      .table_zi2 {
        margin-top: 10px;
        width: 171.34px;
        height: 16px;
        // background-color: blue;
        text-align: center;
        line-height: 16px;
        font-size: 12px;
        .abc {
          color: red;
          font-weight: bold;
        }
      }
    }
  }
}

.left .bottom_left {
  margin-top: 15px;
  width: 1087px;
  height: 475px;
  background-color: rgb(255, 255, 255);
}

.right {
  width: 300px;
  height: 640px;
  /* background-color: red; */
  margin-top: 0px;
  margin-left: 20px;
}

.right .top_right {
  margin-top: 10px;
  width: 300px;
  height: 315px;
  background-color: rgb(255, 255, 255);
  .top_right1 {
    width: 100%;
    height: 30px;
    //   background-color: blueviolet;
    font-size: 14px;
    color: #333;
    line-height: 30px;
    margin-left: 10px;
  }
  .top_right2 {
    width: 285px;
    height: 22px;
    //   background-color: blueviolet;
    margin: auto;
    margin-top: 5px;
    display: flex;
    margin-left: 15px;
    .zi1 {
      width: 52.31px;
      height: 22px;
      background-color: #dcecfc;
      text-align: center;
      line-height: 22px;
      color: #0387ff;
      font-size: 12px;
    }
    .zi2 {
      width: 200px;
      height: 16px;
      //   background-color: brown;
      margin-top: 5px;
      margin-left: 15px;
      font-size: 12px;
    }
  }
}

.right .bottom_right {
  margin-top: 15px;
  width: 300px;
  height: 300px;
  background-color: rgb(255, 255, 255);
  overflow: scroll;
  .bottom_right1 {
    width: 100%;
    height: 30px;
    // background-color: chartreuse;
    font-size: 14px;
    color: #333;
    line-height: 30px;
    margin-left: 10px;
  }
  .bottom_right2 {
    margin-left: 10px;
    width: 285px;
    height: 37.4px;
    // background-color: chocolate;
    border-bottom: 1px rgb(238, 238, 238) solid;
    .bottom_right2_img {
      width: 30px;
      height: 30px;
      background-color: cornflowerblue;
      float: left;
      border-radius: 4px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .left_right {
      width: 225px;
      height: 13.6px;
      //   background-color: darkcyan;
      float: left;
      margin-top: 10px;
      margin-left: 10px;
      display: flex;
      justify-content: space-between;
      .left {
        width: 50px;
        height: 100%;
        font-size: 12px;
        color: #333;
        //   background-color: blue;
      }
      .right {
        width: 65px;
        height: 100%;
        font-size: 12px;
        color: #333;
        //   background-color: chartreuse;
      }
    }
  }
}
</style>